requirejs(['sysmanMain','fullcalendar','fullcalendar_zh-cn','dateUtil','portal','flowEditModule','domReady!'],
			function(main,fullcalendar,lang,dateUtil,portal,flowEditModule,doc){

	var rootid = 'oa-main-tab';
	
	var window_id = 'main-issue-window';
	
	//news container
	var _news = $('#'+rootid + ' div.doc-news' );
	
	//meetings container
	var _meetings = $('#'+rootid + ' div.doc-meetings');
	
	//issue container
	var _issue = $('#'+rootid + ' div.operator-issue');
	
	//schedule container
	var _schedule = $('#'+rootid + ' div.schedule');
	
	//日程查询url
	var qryDutyUrl='/'+main.getRootPath()+'/oaDutyList/query/getDutyList.action';
	
	//通知查询url
	var qryDocUrl ='/portal/getTypeListDomain';
	
	//会议查询url
	var qryMeetingUrl ='/'+main.getRootPath()+'/oaConferenceroomApply/query/getFinishedListDomain.action';
	
	//事项查询url
	var queryIssueUrl = '/'+main.getRootPath()+'/workFlow/query/flowOperateListDomain.action';
	
	
	var edit_window_config = {
		oaCarApply:'oa-carapply-win',
		oaConferenceroomApply:'oa-conferenceroomapply-win',
		oaDeptpayment:'oa-deptpayment-win',
		oaDispatchManagement:'oa-dispatchmanagement-win',
		oaDrugPurchase:'oa-drugpurchase-win',
		oaEquipmentPurchase:'oa-equipmentPurchase-win',
		oaEquipmentRepaire:'oa-equipmentrepaire-win',
		oaHighvalue:'oa-highvalue-win',
		oaIncomingDispatches:'oa-incomingdispatches-win',
		oaInfrastructure:'oa-infrastructure-win',
		oaInfrastructureRepaire:'oa-infrastructurerepaire-win',
		oaLeaver:'oa-leaver-win',
		oaLogisticsPurchase:'oa-logisticspurchase-win',
		oaNewDrugPurchase:'oa-newdrugpurchase-win',
		oaPersonnelAppointment:'oa-personnelappointment-win',
		oaPersonnelRecruitment:'oa-personnelrecruitment-win',
		oaSeniorTitleAppointment:'oa-seniortitleappointment-win',
		oaTempDrugPurchase:'oa-tempdrugpurchase-win'
	}
	
	var btn_listen = {
			
			notification_btn_listenner : function(e) {
//				alert('click me ...');
				var _el = e.delegateTarget;
				
				var _param ={};
				if(_el){
					_param.id = $(_el).attr("docid");
				}
				
				//保存阅读回执
				$.ajax({
					url: '/'+main.getRootPath()+'/docread/save.action',
					type:'post',					
					data:_param,																		
					success:function(data){},
					failure:function(){
						msgServ.Msgslide('阅读回执记录失败！')
					}
				})
				//弹窗显示通知内容				
				portal.openPage(e);			

			},
			//监听函数定义
			meeting_btn_listenner : function(e) {
				
				//弹窗显示会议信息

			}
	}
	var funcDef = {
		init:function(){
			//初始化通知公告		
			funcDef.initList({typeCode:'notification',target:_news});
			
			//初始化会议通知
			funcDef.initMeeting();
			
			//初始化待办事项		
			funcDef.initIssue();
			
			//初始化日程安排
			funcDef.initSchedule();
		},
		
		//初始化通知公告
		initList:function(_options){
			
			
			var _param={condition:{typeCode:_options.typeCode}};
			
			$.ajax({
				url: qryDocUrl,
				type:'post',
				async:false,
				data:_param,																		
				success:function(data){
					
					if(data && data.total>0){
						var _html = '';
						var html_title = '';
						
						var _date ='';
						
						$.each(data.rows,function(i,e){								
							var _time = '';
							if(e && e.public_date){
								var _darr = e.public_date.split(' ');
								if(_darr[0]){
									if(_date!=_darr[0]){
										_date = _darr[0];
										_html += '<div class="row red" style="padding-left:15px;">'+_date+'</div>';
									}
								}
								if(_darr[1]){
									_time = _darr[1];
								}
							}
	
							_html += '<div class="row">'+
								'<div class="col-md-8 col-sm-7">'+
								'<a href=\"javascript:void(0);\" docid=\"'+ e.id + '\" class=\"notification-file\" lobid=\"' + e.lobid +'\">'+
								'<div class="articles_contents">'+'* '+ e.name + '</div>'+
								'</a>'+
								'</div>'
							_html += '<div class="col-md-4 col-sm-5"><div class="articles_date">'+ _time+ '</div></div>'+
								'</div>'
						})
						_html = html_title + _html;
						
						(_options.target).append(_html);
						
						//判断按钮是否存在
						var btn = $('#'+rootid +' a.notification-file')
						
						if(btn.length>0){
							if(window.console){
								console.log ('bind click me ...'+ btn.length)
							}
							$(btn).unbind('click');
							$(btn).bind('click', btn_listen.notification_btn_listenner)	
						}
					}
													
				},
				failure:function(result){
					if(window.console){
						console.log('ajax call failured ...')
					}
				}
			})
			
			
			
		},
		
		//初始化会议通知
		initMeeting:function(){
						
			
			$.ajax({
				url: qryMeetingUrl,
				type:'post',
				async:false,																		
				success:function(data){
					
					if(data && data.total>0){
						var _html = '';
						var html_title = '';
						
						var _date ='';
						
						$.each(data.rows,function(i,e){								
							var _time = '';
							if(e && e.start_room_time){
								var _darr = e.start_room_time.split(' ');
								if(_darr[0]){
									if(_date!=_darr[0]){
										_date = _darr[0];
										_html += '<div class="row red" style="padding-left:15px;">'+_date+'</div>';
									}
								}
								if(_darr[1]){
									_time = _darr[1];
								}
							}
							
							//会议内容
							_html += '<div class="row">'+
								'<div class="col-md-6">'+
								'<a href=\"javascript:void(0);\" docid=\"'+ e.id + '\" class=\"js-meeting-file\"\">'+
								'<div class="articles_contents">'+'* '+ e.room_content + '</div>'+
								'</a>'+
								'</div>'
							//主持科室
							_html += '<div class="col-md-3"><span class="js-meeting-dept">'+e.apply_deptname +'</span></div>'
							
							//会议时间
							_html += '<div class="col-md-3"><div class="articles_date">'+ _time+ '</div></div>'+
								'</div>'
						})
						_html = html_title + _html;
						
						_meetings.append(_html);
					}
					
					//判断按钮是否存在
					var btn = $('#'+rootid +' a.meeting-file')
					if(btn.length>0){
						$(btn).unbind('click');
						$(btn).bind('click', btn_listen.meeting_btn_listenner)	
					}
													
				},
				
				
				
				failure:function(result){
					if(window.console){
						console.log('ajax call failured ...')
					}
				}
			})
			
		},
		
		//初始化待办事项
		initIssue:function(){
			
			var _param={
				url :queryIssueUrl,
				rownumbers:true,
				pagination:true,
				idField: 'flowinstid',
				fitColumns: true,
				//onClickCell:private_method.editCell,
				columns:[[
//					{field:'ck',checkbox:"true"},        
					{field:'biz_name',title:'事项类型',halign:'center',width:30},
					{field:'apply_deptname',title:'申请科室',halign:'center',width:30},        
					{field:'apply_name',title:'申请人',width:30,align:'center',halign:'center'},
					{field:'name',title:'具体事项',width:60,align:'center',halign:'center'},
					{field:'apply_date',title:'申请时间',width:60,align:'center',halign:'center'},
					{field:'nodename',title:'当前环节',halign:'center',width:30},        
					{field:'create_time',title:'环节时间',width:30,align:'center',halign:'center'}
				]],
				onDblClickRow:funcDef.gridDblClick
			}
			
			_issue.datagrid(_param);
		},
		/**
		 * grid双击事件
		 */
		gridDblClick:function(index,row){
//			alert(' double click grid fired ,biz code:  ' + row.business_key);
			if(row && row.bizcode){
				var _bizcode = row.bizcode
				
				var _fullbizcode = row.business_key;
				
				var _modConfig = main.getModuConf(_fullbizcode)
				
				if(_modConfig){
					
					//获取业务数据
					var qryUrl = '/'+main.getRootPath()+'/'+row.bizcode+'/query/getOne.action';
					var editUrl = '/'+main.getRootPath()+'/'+row.bizcode+'/editPage.action';
					$.ajax({
						url:qryUrl,
						data:{id:row.id},
						success:function(data){
							data.flowStatus = 2;
							_modConfig.data = data;
							main.setModuConf(_fullbizcode,_modConfig);
							var _window  
							
							if(edit_window_config[_bizcode]){
								_window = $('#'+edit_window_config[_bizcode]);
							}else{
								_window = $('#'+window_id);
							}
							var _param = {
								window:_window,
								href:editUrl,
								width:900,
								height:700}
							
							var _height = $(document).height();
							var _width = $(document).width();
							
							if(_height && _height<=700){
								_param.height = _height-50
							}
							_param.onClose=function(){
								$('#'+window_id).empty();
								flowEditModule.setBizConfig(null);
							}
							flowEditModule.setBizConfig(_modConfig)
							_window.window(_param)
							_window.window('vcenter').window('hcenter')
							
							_window.window('open')
						}
						
					})
					
				}
			}
		},
		//初始化日程安排
		initSchedule:function(){
			
			
			if(window.console){
				console.log('init schedule...');
			}
			_schedule.fullCalendar({
				defaultView: 'agendaDay',				
				editable: true,
				eventLimit: true, // allow "more" link when too many events
				lang: 'zh-cn',			   
			    events: qryDutyUrl,
		        eventClick: function(events, jsEvent, view) {
		        	if(events && events._id){
			        	var _param = {
							url :'/'+sysmanMain.getRootPath()+'/oaDutyList/query/getOne.action?id='+events._id,					
							type : 'post',
							contentType : "appliction/json;charset=utf-8",
							success:funcDef.refreshForm,
							error:function(){
								msgServ.Msgslide('操作失败！')
							}
						}
						$.ajax(_param)
					}			        	
				}				    
			});	
			
		}
	}
	
	funcDef.init();

})